package com.mall.shopping.services;

import com.mall.shopping.IProductCateService;
import com.mall.shopping.constants.ShoppingRetCode;
import com.mall.shopping.converter.ProductCateConverter;
import com.mall.shopping.dal.entitys.ItemCat;
import com.mall.shopping.dal.persistence.ItemCatMapper;
import com.mall.shopping.dto.AllProductCateRequest;
import com.mall.shopping.dto.AllProductCateResponse;
import com.mall.shopping.dto.ProductCateDto;
import com.mall.shopping.utils.ExceptionProcessorUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @Name : IProductCateServiceImpl.java
 * @Time : 2021/8/25 17:20
 * @Author : Xfeng
 * @Software : IntelliJ IDEA
 */
@Service
@Slf4j
public class IProductCateServiceImpl implements IProductCateService {

    @Autowired
    private ItemCatMapper itemCatMapper;

    @Autowired
    private ProductCateConverter productCateConverter;

    @Override
    public AllProductCateResponse getAllProductCate(AllProductCateRequest request) {
        AllProductCateResponse response = null;
        try {
//        String sort = request.getSort();
            request.requestCheck();
            List<ItemCat> allProductCate = itemCatMapper.getAllProductCate();
            List<ProductCateDto> productCateDtos = productCateConverter.item2Dto(allProductCate);
            response = new AllProductCateResponse();
            response.setProductCateDtoList(productCateDtos);
            response.setCode(ShoppingRetCode.SUCCESS.getCode());
            response.setMsg(ShoppingRetCode.SUCCESS.getMessage());
        } catch (Exception e) {
            log.error("IProductCateServiceImpl.getAllProductCate occur Exception :" + e);
            ExceptionProcessorUtils.wrapperHandlerException(response, e);
        }

        return response;
    }
}
